-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Index.equals raising with index of tuples that contain NA #48446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pandas/_libs/missing.pyx
Outdated
return False | ||
|
||
for left_element, right_element in zip(left, right): | ||
if left_element is C_NA and not right_element is C_NA: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not right_element is C_NA
-> right_element is not C_NA
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
@@ -659,7 +660,11 @@ def array_equivalent_object(left: object[:], right: object[:]) -> bool: | |||
and not (isinstance(x, type(y)) or isinstance(y, type(x)))): | |||
# Check if non-scalars have the same type | |||
return False | |||
elif check_na_tuples_nonequal(x, y): | |||
# We have tuples where one Side has a NA and the other side does not | |||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment that this is the only/main we we expect to get a TypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
if not isinstance(left, tuple) or not isinstance(right, tuple): | ||
return False | ||
|
||
for left_element, right_element in zip(left, right): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this assert that len(left) == len(right)
? Guessing this is assumed upstream but technically (1, NA)
and (1,)
would return False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added. I think we could end up here with weird combinations, so better to be a bit more explicit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# Conflicts: # pandas/_libs/lib.pyx
Ok to merge on greenish? |
Thanks @phofl |
@@ -168,7 +168,7 @@ Indexing | |||
|
|||
Missing | |||
^^^^^^^ | |||
- | |||
- Bug in :meth:`Index.equals` raising ``TypeError` when :class:`Index` consists of tuples that contain ``NA`` (:issue:`48446`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this is not rendering correctly due to unbalanced backticks around TypeError.
…s-dev#48446) * BUG: Index.equals raising with index of tuples that contain NA * Adress review * Add sanity check
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.This came up when working on MultiIndex.union with ea. Gets converted into a Index of tuples and then raising the error. The added check is a last resort before raising to avoid impacting performance negatively.